package com.dz.common.base;

import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import java.io.Serializable;
import java.util.List;

@Builder
@Setter
@Getter
@NoArgsConstructor
public class BasePageResultsVO<T> implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 4536042441084321849L;

	public BasePageResultsVO(Integer pageNum, Integer pageSize, Long total, List<T> list, String message) {
		setPageNum(pageNum);
		setPageSize(pageSize);
		setTotal(total);
		setMessage(message);
		setList(list);
	}

	@Builder.Default()
	private Integer pageNum = 1;
	@Builder.Default()
	private Integer pageSize = 10;

	private Long total;

	transient List<T> list;

	private String message;

	public static <T> BasePageResultsVO<T> success(long total, List<T> list) {
		return BasePageResultsVO.<T>builder().total(total).list(list).build();
	}

	public static <T> BasePageResultsVO<T> success(Integer pageNum, Integer pageSize, long total, List<T> list) {
		return BasePageResultsVO.<T>builder().pageNum(pageNum).pageSize(pageSize).total(total).list(list).build();
	}

	public static <T> BasePageResultsVO<T> fail(String mesg) {
		return BasePageResultsVO.<T>builder().message(mesg).build();
	}
}
